﻿

--划百度客户
CREATE PROCEDURE [dbo].[proc_WHCustomer_Paddle]
	(
		@CusId varchar (4000),
		@CusName nvarchar(50),
		@UserName nvarchar(50),
		@EName nvarchar(50),
		@CreateName nvarchar(50)
	)

AS

	BEGIN	
		
		declare @str NVARCHAR (max),@str1  NVARCHAR (max)
		
		set @str='		
		
		--更新order表
		update [order] set trackkfaccount='''+@UserName+''',trackkfname='''+@EName+''',trackkfdepid=(select top 1 departmentid from employee where username='''+@UserName+''' order by id desc)
		      where cusid in ('+@CusId+')
		
		
		--更新客户表
		update customer set ServicePerson='''+@UserName+''',ServicePersonEName='''+@EName+''',ServiceDate=getdate()
		where CustomerId in ('+@CusId+') '
		
		set @str1='
		--插入日志表
		Insert Into Customer_HuaTemp(CusId,CusName,UserName,EName,CreateName,CreateDate,CusInfo,flag) 
		select CustomerId,CustomerName,'''+@UserName+''','''+@EName+''','''+@CreateName+''',getdate(),
		''[''+ServicePerson+''],[''+ServicePersonEName+''],[''+ISNULL(Convert(varchar,ServiceDate,120),'''')+'']'',2
		 from Customer where CustomerId in ('+@CusId+') 
		 '
		 exec(@str)
		 exec(@str1)
		-- print (@str) 		
	End
	
	RETURN

